package BackTrackingPackage;

import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * @author Lzm
 * @version 1.0
 */
/*此题和前面题不一样的地方在于, 每次的集合都不一样*/
public class letterCombinations_ {
  String list = "";
  List<String> result = new ArrayList<>();
  String[] numString = {"", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
  @Test
  public void letterCombinationsTest(){
    backTracking("23",0);
    System.out.println(result);
  }
  public void backTracking(String digits,int index) {
      if (list != null ){
        if (index == digits.length()){
          result.add(list);
          return;
        }
      }
      String newString = numString[digits.charAt(index) - '0'];
      for (int i = 0 ; i < newString.length() ; i++){
        list += newString.charAt(i) ;
        backTracking(digits,index + 1);
        list = list.substring(0,list.length() - 1);
      }
  }
}
